import { defineStore } from 'pinia'

export const useWsStore = defineStore('ws', {
  state: () => {
    return {
      roboArm: {},
      moveCapture: [],
      history: [],
      tm: {},
      navigate: {},
      carrySystem: {}
    }
  },
  actions: {
    setWs (url, val) {
      const item = url.replace("/", "")
      const jsonVal = JSON.parse(val)
      if(jsonVal != null) {
        this[item] = jsonVal
      }
    },
    setArrToObj (url, val) {
      const item = url.replace("/", "")
      const jsonVal = JSON.parse(val)
      if(Array.isArray(jsonVal)) {
        for(const dom of jsonVal) {
          this[item][dom['name']] = dom
        }
      }
    }
  }
})